<template>
	<view class="set-page">
		<u-navbar title="设置" :autoBack="true" :placeholder="true" bgColor="rgba(255,255,255,0)"></u-navbar>
		<view class="content">
			<view class="set-box">
				<view class="set-item" @click="goNavto('/pages/my/set/account/index')">
					<view class="item-left">
						<image src="https://m.lqvvvv.com/assets/static/my/set-icon1.png" mode="heightFix"></image>
						<view class="item-text">
							账号与安全
						</view>
					</view>
					<view>
						<u-icon name="arrow-right" color="#8B8DA0" size="16"></u-icon>
					</view>
				</view>
				<view class="set-item" @click="goclear">
					<view class="item-left">
						<image src="https://m.lqvvvv.com/assets/static/my/set-icon2.png" mode="heightFix"></image>
						<view class="item-text">
							消除缓存
						</view>
					</view>
					<view></view>
				</view>
				<view class="set-item" @click="goagreement('registrer_agreement')">
					<view class="item-left">
						<image src="https://m.lqvvvv.com/assets/static/my/set-icon3.png" mode="heightFix"></image>
						<view class="item-text">
							服务协议
						</view>
					</view>
					<view>
						<u-icon name="arrow-right" color="#8B8DA0" size="16"></u-icon>
					</view>
				</view>
				<view class="set-item" @click="goagreement('privacy_agreement')">
					<view class="item-left">
						<image src="https://m.lqvvvv.com/assets/static/my/set-icon4.png" mode="heightFix"></image>
						<view class="item-text">
							隐私政策
						</view>
					</view>
					<view>
						<u-icon name="arrow-right" color="#8B8DA0" size="16"></u-icon>
					</view>
				</view>
				<!-- 				<view class="set-item">
					<view class="item-left">
						<image src="https://m.lqvvvv.com/assets/static/my/set-icon5.png" mode="heightFix"></image>
						<view class="item-text">
							资质证明
						</view>
					</view> 
					<view>
						<u-icon name="arrow-right" color="#8B8DA0" size="16"></u-icon>
					</view>
				</view> -->
				<view class="set-item">
					<view class="item-left">
						<image src="https://m.lqvvvv.com/assets/static/my/set-icon6.png" mode="heightFix"></image>
						<view class="item-text">
							个性化推荐
						</view>
					</view>
					<view>
						<u-switch v-model="value" @change="change" active-color="#5755F2"></u-switch>
					</view>
				</view>
				<view class="set-item">
					<view class="item-left">
						<image src="https://m.lqvvvv.com/assets/static/my/set-icon6.png" mode="heightFix"></image>
						<view class="item-text">
							青少年模式
						</view>
					</view>
					<view>
						<u-switch v-model="value1" asyncChange @change="change1" active-color="#5755F2"></u-switch>
					</view>
				</view>
			</view>
			<view class="tisp">
				<view>增值电信业务经营许可证 闽B2-20241840</view>
				<view>备案号:闽ICP备2024065288号-2A</view>
				<view>@2025 旅趣 福州市乐娱信息科技有限公司 版权所有</view>
			</view>
			<u-button text="退出登陆" class="out" color="#5755F2" shape="circle" @click="goout" type="primary"></u-button>
		</view>
		<u-popup :show="show" @close="close" mode="center" round="10">
			<view class="popup">
				<view class="popup-title">{{title}}</view>
				<view>
					<u--input placeholder="请输入6位数密码" maxlength="6" type="number" border="surround" v-model="value2"></u--input>
				</view>
				<view class="popup-btn">
					<u-button type="primary" text="确定" @click="gopass" color="#5755F2" shape="circle"></u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				value: false,
				value1: false,
				value2: '',
				info: {},
				title: ''
			}
		},
		onLoad() {
			this.getuserinfo()
		},
		methods: {
			close() {
				this.show = false
			},
			getuserinfo() {
				this.$Request({
					method: 'POST',
					url: '/api/user/getMyInfo',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data
						this.value = this.info.is_personalization == 1 ? true : false
						this.value1 = this.info.is_adolescent == 1 ? true : false
					} else {
						this.info = {}
					}
				})
			},
			goagreement(name) {
				this.$navTo.togo('/pages/my/agreement/index', {
					name: name
				})
			},
			goclear() {
				uni.showModal({
					title: '提示',
					content: '确定清除缓存吗?会导致您重新登录！',
					confirmText: '立即清除',
					success(res) {
						if (res.confirm) {
							uni.clearStorageSync();
							uni.showToast({
								title: '清除成功'
							});
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/login/index'
								})
							}, 1000)
						}
					}
				});
			},
			gopass() {
				if (this.value2 < 6) {
					uni.showToast({
						title: '请输入6位数密码！',
						icon: 'none'
					})
					return
				}
				if(this.title == '请设置密码！'){
					let params = {
						adolescent_password:this.value2,
						is_adolescent:1
					}
					this.$Request({
						method: 'POST',
						url: '/api/user/profile',
						data: params,
						ismsg: true,
					}).then(res => {
						if (res.code == 1) {
							this.value2 = ''
							this.getuserinfo()
							this.show = false	
						}
					})
				}else{
					if(this.value2 != this.info.adolescent_password){
						uni.showToast({
							title:'密码错误！',
							icon:'none'
						})
					}else{
						let params = {
							is_adolescent:0
						}
						this.$Request({
							method: 'POST',
							url: '/api/user/profile',
							data: params,
							ismsg: true,
						}).then(res => {
							if (res.code == 1) {
								this.value2 = ''
								this.getuserinfo()
								this.show = false	
							}
						})
					}
				}
			},
			change1(e) {
				if (this.info.adolescent_password == '') {
					this.title = '请设置密码！'
					this.show = true
				} else {
					if (e == true) {
						let params = {
							is_adolescent:1
						}
						this.$Request({
							method: 'POST',
							url: '/api/user/profile',
							data: params,
							ismsg: true,
						}).then(res => {
							if (res.code == 1) {
								this.getuserinfo()
							}
						})
					} else {
						this.title = '请验证密码！'
						this.show = true
					}
				}
			},
			change(e) {
				let params = {
					is_personalization: e == false ? 0 : 1
				}
				this.$Request({
					method: 'POST',
					url: '/api/user/profile',
					data: params,
					ismsg: true,
				}).then(res => {
					if (res.code == 1) {
						this.getuserinfo()
					}
				})
			},
			goout() {
				uni.removeStorageSync('token')
				uni.showToast({
					title: "退出成功",
					icon: 'none'
				})
				// #ifdef MP-WEIXIN
				this.ws.logout()
				uni.reLaunch({
					url:'/pages/login/index'
				})
				// #endif
				// #ifdef APP || H5
				this.ws.logout()
				// #endif
			},
			goNavto(url) {
				this.$navTo.togo(url)
			}
		}
	}
</script>

<style>
	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.set-page {
		min-height: 100vh;
		background-image: url('https://m.lqvvvv.com/assets/static/index/nav-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 800rpx;

		.popup {
			width: 500rpx;
			padding: 30rpx;

			.popup-title {
				font-size: 28rpx;
				font-weight: 900;
				text-align: center;
				margin-bottom: 30rpx;
			}

			.popup-btn {
				margin-top: 30rpx;
			}
		}

		.tisp {
			text-align: center;
			font-size: 26rpx;
			margin-bottom: 30rpx;
			color: #999;
			view{
				margin-bottom: 10rpx;
			}
		}

		.content {
			padding: 30rpx;

			.out {
				margin-top: 100rpx;
			}

			.set-box {
				padding: 30rpx 30rpx 0;
				border-radius: 30rpx;
				background-color: #fff;

				.set-item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding-bottom: 30rpx;
					margin-bottom: 30rpx;
					border-bottom: 1rpx solid #F7F7F7;

					.item-left {
						display: flex;
						align-items: center;

						image {
							width: 34rpx;
							height: 36rpx;
						}

						.item-text {
							font-size: 28rpx;
							color: #000000;
							margin-left: 50rpx;
						}
					}
				}

			}
		}
	}
</style>